import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Bind } from './bind.schema'
import { Model } from 'mongoose'

@Injectable()
export class BindService {

    // 模型注入
    constructor(@InjectModel(Bind.name) private BindSchema: Model<Bind>) {
    }
    //添加品牌
    async addBind(body: any) {
        
        await this.BindSchema.create(body)
        return "添加成功" 
    }
    //查询
    async getBind(searchList:any[]) {
        let data
        if (searchList.length > 0) {
            data = await this.BindSchema.find({ $and: searchList }) // 使用

        } else {
            data = await this.BindSchema.find() // 使用
        }

        return data
    } 
    //更改状态
    async updateStatus(body: any) {
        await this.BindSchema.updateOne({ _id: body._id }, { isorder:!body.isorder })
        return  "修改成功"
    }
    //更改状态
    async updateStatus2(body: any) {
        await this.BindSchema.updateOne({ _id: body._id }, { istodelivery:!body.istodelivery })
        return "修改成功"
    }

 
    //修改  
    async updateBind(body: any) {
        await this.BindSchema.updateOne({ _id: body._id }, body)
        return  "修改成功"
    }
    //删除
    async deleteBind(body: any) {
        await this.BindSchema.deleteOne({ _id: body._id })
        return "删除成功"
    }

    
}